package com.sx.pipeline.ui.task.approve

import android.view.View
import androidx.viewpager2.widget.ViewPager2
import com.alibaba.android.arouter.facade.annotation.Route
import com.google.android.material.tabs.TabLayoutMediator
import com.sx.mvvmlibs.bus.RxBus
import com.sx.pipeline.BR
import com.sx.pipeline.R
import com.sx.pipeline.app.base.CYDataBindingBaseActivity
import com.sx.pipeline.app.event.TypeEvent
import com.sx.pipeline.arouth.RoutePath
import com.sx.pipeline.databinding.ActReleaseTaskListBinding
import com.sx.pipeline.ui.task.approve.frag.ApproveTaskPageAdapter


/**
 * @Author: YY
 * @Date: 2022/4/5
 * @Description: 我审批的任务-任务列表
 */
@Route(path = RoutePath.Mine.APPROVE_TASK_LIST)
class ApproveTaskListActivity : CYDataBindingBaseActivity<ActReleaseTaskListBinding, ApproveTaskVM>(
    R.layout.act_release_task_list), View.OnClickListener {
    private lateinit var releasePageAdapter: ApproveTaskPageAdapter


    override fun initData() {
        mBinding.setVariable(BR.onClick, this)
        mBinding.titleBar.title=getString(R.string.txt_my_approve_task)
        mBinding.titleBar.leftView.setOnClickListener {
            finish()
        }
        initPager()
    }

    /**
     * 初始化ViewPager
     */
    private fun initPager() {
        if (mBinding.viewPager.adapter == null) {
            releasePageAdapter = ApproveTaskPageAdapter(
                mViewModel.getApproveTabsList(),mViewModel.getApproveTabsId(), supportFragmentManager, lifecycle)
        }
        mBinding.viewPager.adapter = releasePageAdapter
        mBinding.viewPager.offscreenPageLimit=mViewModel.getApproveTabsList().size
        mBinding.viewPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {

            }
        })
        //绑定tabLayout和viewPager
        TabLayoutMediator(
            mBinding.tab, mBinding.viewPager,
            true, true
        ) { tab, position ->
            tab.text = mViewModel.getApproveTabsList()[position]
        }.attach()
    }

    override fun onClick(v: View?) {
        when (v?.id) {

        }
    }
    override fun onDestroy() {
        super.onDestroy()
    }
}